//获取应用实例
var common_Js = require("../../../component/common.js")
import Toast from '../../../component/vant/toast/toast';
var app = getApp(), fetchApi = require("../../../utils/httpPost.js")
import Dialog from '../../../component/vant/dialog/dialog';
const format = rate => Math.min(Math.max(rate, 0), 100);
Page({
  data: {
    imgurl: app.getImgUrl(),
    quantity1: {
      quantity: 1,
      min: 1,
      max: 20
    },
    skuMaxCount:2,
    id: 0,
    scrollTop: 0,
    imgUrls: [],//商品图片
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    scrollHeight: 0,
    btnWidth: 0,
    showDialog: false,
    goodsData: [],//商品信息
    guiges: [],//规格集合
    descContentList:[],
    appraiseCount:0,
    isShowSku:true,
    isShowSkuPop:false,
    skus:[],//sku列表
    productInfo:[],//商品基础信息
    productValue:[],//规格列表
    productAttr:[],//规格类型
    appraises: [],
    details: [],
    currentState: '',
    goBuyType: "addCart",
    skuStock:0,
    isAllCheck:false,
    chooseSkuId:'',
    chooseSkuImg:'',
    chooseSkuIndex: 0,
    chooseSkuCount: 1,//sku 当前的数量
    chooseSkuTxt:'',
    chooseSku:{},//当前选中的 sku 对象
    chooseSkuAttr:'',
    chooseSkuAttrPrice:0,
    chooseSkuAttrOtPrice:0,
    proprietorSplit:0,
    isVisit:0,
    isAppointment:0,
    islimitCount:false,
    buyLimitCount:0,
    hasCard:false,
    isiphonex: app.globalData.isiphonex,
    isxiaomi: app.globalData.isxiaomi,
    isCollect: false,
    loading: false,
    netWork: false,
    isLoading: true,
    openData:[],
    fromType: '',
    visibleModal: false, 
    product:{},
    cart_count:0,
    authSetModalText:
    [
      { name: '取消', },
      { name: '确认购买',  color: '#ed3f14', loading: false }
    ],
    gradientColor: {
      '0%': '#ffd01e',
      '100%': '#ee0a24'
    },
    totalPrice:0.00,
    totalOtPrice:0.00,
    priceDikou:'',
    mer:{},
    query:'',
    watchAdDetailSecond:15,
    time: 16 * 1000,
    timeData: {},
    valueCircle:0,
    isShowCountDown:true,
    is_add_feed_record:0,
    user_id:0,
    ag_id:0,
    codeUrlbg:'https://caihengyun.obs.cn-north-9.myhuaweicloud.com/simple/image/invite_share_qr_code-1.jpg',//背景图片
    canvas:null,
    ctx:null,
    scale:0.5,
    attrValueCount:0,

  },
  onLoad: function (options) {
    console.log("options",options)
    var that = this;
    if(options.q){
      var q = decodeURIComponent(options.q) // 获取到二维码原始链接内容
      const scancode_time = parseInt(options.scancode_time) // 获取用户扫码时间 UNIX 时间戳
      
      q = "?" + q.split("?")[1];
      this.data.query = q;
      console.log('q',q)
      options = this.getQueryVariable(q);
      console.log('options',options)
      var id = parseInt(options.id) 
      that.data.id = id
    }else{
      var id = parseInt(options.id) 
      that.data.id = id
      this.data.query = "?id=" + id;
    }

    if(options.ag_id){
      this.data.ag_id = parseInt(options.ag_id)
    }

    that.onHttpInit()
    that.data.choosedSkuId = 0
    that.setData({
      scrollHeight: app.globalData.windowHeight+4,
      btnWidth: app.globalData.windowWidth,
      isShowSkuPop:false
    })
  },
  getQueryVariable(url){
    //返回当前 URL 的查询部分（问号 ? 之后的部分）。
    var urlParameters = url;// location.search;
    //声明并初始化接收请求参数的对象
    var requestParameters = new Object();
    var parameterArray = [];
    //如果该求青中有请求的参数，则获取请求的参数，否则打印提示此请求没有请求的参数
    if (urlParameters.indexOf('?') != -1)
    {
        //获取请求参数的字符串
        var parameters = decodeURI(urlParameters.substr(1));
        //将请求的参数以&分割中字符串数组
        parameterArray = parameters.split('&');
        //循环遍历，将请求的参数封装到请求参数的对象之中
        for (var i = 0; i < parameterArray.length; i++) {
            requestParameters[parameterArray[i].split('=')[0]] = (parameterArray[i].split('=')[1]);
        }
        console.info('theRequest is =====',requestParameters);
    } else
    {
        console.info('There is no request parameters');
    }
    return requestParameters;
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/product/detail', {
      product_id: that.data.id
    }, function (res) {
      if (res.data.code == 0) {
        console.log("商品详情数据", res.data.data);
        that.data.descContentList = res.data.data.description;
        that.data.productValue = res.data.data.product.productValue;
        that.data.islimitCount = res.data.data.product.isLimit;
        that.data.buyLimitCount = res.data.data.product.limitCount;
        that.data.productAttr = res.data.data.product.productAttr;
        that.data.mer = res.data.data.mer;
        that.data.product = res.data.data.product;
        that.data.attrValueCount = res.data.data.product.productAttr.length;
        console.log('res.data.data.product.isVisit',res.data.data.product.isVisit);
        that.setData({
          product: res.data.data.product,
          productAttr: res.data.data.product.productAttr,
          productValue : res.data.data.product.productValue,
          chooseSkuImg: res.data.data.product.image,
          cart_count:res.data.data.cart_count,
          productInfo: res.data.data.product,
          is_add_feed_record: res.data.data.is_add_feed_record,
          watchAdDetailSecond: res.data.data.watchAdDetailSecond,
          time: res.data.data.watchAdDetailSecond!=undefined ? res.data.data.watchAdDetailSecond * 1000: 16* 1000,
          isAppointment: res.data.data.product.isAppointment,
          isVisit: res.data.data.product.isVisit,
          imgUrls: res.data.data.product.sliderImageArray,
          currentState: "1/" + res.data.data.product.sliderImageArray.length,
          skuStock:res.data.data.product.totalCount,
          isCollect: res.data.data.isCollect > 0 ? true: false,
          mer: res.data.data.mer,
          user_id:res.data.data.user_id,
        });
        that.setData({ isLoading: false, loading: true, netWork: true, }) 
        that.autoClickSku();
      } else {
        console.log("商品详情数据 异常", res.data.msg)
      }
    },function(){
      that.setData({ isLoading: false, loading: true, netWork: true, }) 
    })
  },
  goLocation:function(){
    var latitude = this.data.mer.latitude
    var longitude = this.data.mer.longitude
    wx.openLocation({
      latitude,
      longitude,
      scale: 17
    })
  },
  showSkuPopAuto:function(e){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    var estate_id = app.getStorageSync("estate_id");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    } else {
      if(this.data.product.isNeedEstate == 1 && estate_id == 0){
        this.handleEstate();
      } else{
        if(this.data.attrValueCount  == 1){
          this.goBuy();
        }else{
          console.log('showSkuPop e',e)
          var buytype = e.currentTarget.dataset.type
          this.setData({
            isShowSkuPop:true, 
            goBuyType:buytype
          })
        }
      }
    }
  },
  /**
   * 显示sku弹框
   */
  showSkuPop:function(e){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    var estate_id = app.getStorageSync("estate_id");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id=' + this.data.ag_id,
      })
    } else {
      if(this.data.product.isNeedEstate == 1 &&estate_id == 0){
        this.handleEstate();
      } else{
        console.log('showSkuPop e',e)
          var buytype = e.currentTarget.dataset.type
          this.setData({
            isShowSkuPop:true, 
            goBuyType:buytype
          })
      }
    }
  },
  /**
   * 计算当前商品的所有的库存量
   */
  getAllSkuStock:function(skus){
    var count = 0
    for (var index in skus){
      var left_count = skus[index].leftCount
      count += left_count
    }
    console.log('skuStock===',count)
    this.setData({ skuStock: count})
  },
  swiper_bindchange: function (t) {
    var a = t.detail.current;
    this.setData({
      currentState: a + 1 + "/" + this.data.imgUrls.length,
      showSwiperNum: a + 2 > this.data.imgUrls.length ? this.data.imgUrls.length : a + 2,
      autoplay: !0
    });
  },
  preImg: function (t) {
    console.log("preSunImg",t)
    var a = t.currentTarget.dataset.imageindex, e = t.currentTarget.dataset.imgdata || [];
    var c = [];
    for(var index in e){
      c.push(e[index].imgUrl)
    }
    common_Js.preImg(a,c)
  },
  autoClickSku:function(){
    console.log('autoClickSku');
    var that = this;
    var attrIndex = 0;
    var valueIndex = 0;
    that.data.productAttr[attrIndex].chooseValueIndex = valueIndex;
    that.data.productAttr[attrIndex].chooseValue = that.data.productAttr[attrIndex].attrValueArr[valueIndex];

    that.data.chooseSkuAttrPrice = that.data.product.attrs[attrIndex].price;
    that.data.chooseSkuAttrOtPrice = that.data.product.attrs[attrIndex].otPrice;
    

    var sku_txt = that.checkSkuTxt(attrIndex,valueIndex);
    that.setData({
      productAttr: that.data.productAttr,
      skuMaxCount: that.data.product.limitCount,
      chooseSkuTxt: sku_txt,
      chooseSkuAttrPrice: that.data.chooseSkuAttrPrice,
      chooseSkuAttrOtPrice: that.data.chooseSkuAttrOtPrice,
    })
    that.getChooseSkuAttr()
  },
  onClickSku:function(t){
    console.log('onClickSku',t);
    console.log('dataset',t.currentTarget.dataset)
    var dataset = t.currentTarget.dataset;
    var that = this;
    var attrIndex = dataset.attrIndex;
    var valueIndex = dataset.valueIndex;
    that.data.productAttr[attrIndex].chooseValueIndex = valueIndex;
    that.data.productAttr[attrIndex].chooseValue = that.data.productAttr[attrIndex].attrValueArr[valueIndex];

    var sku_txt = that.checkSkuTxt(attrIndex,valueIndex);
    that.setData({
      productAttr: that.data.productAttr,
      skuMaxCount: that.data.product.limitCount,
      chooseSkuTxt: sku_txt,
    })
    that.getChooseSkuAttr()
  },
  checkSkuTxt: function (attrIndex,valueIndex) {
    var that = this;
    var txt = ''
    for (var index in this.data.productAttr) {
      console.log('index',index)
      var attr = this.data.productAttr[index];
      console.log('attr.attrValue[index]',attr.attrValue[index])
      if(attr.chooseValueIndex < 0){
        txt = '';
        break;
      }else{
        txt += attr.chooseValue + ",";
      }
      var attrValue = attr.attrValue
      for(var vIndex in attrValue){
        attrValue[vIndex].check = false;
        if(vIndex == valueIndex){
          attr.attrValue[vIndex].check = true;
        }
      }
    }
    console.log('txt',txt)

    if(txt!=''){
      txt = txt.substring(0,txt.length - 1);
      var sku = that.data.productValue[txt];
      console.log('sku',sku)
      
      var proprietorSplit = sku.proprietorSplit;
      console.log('proprietorSplit',proprietorSplit)
      that.setData({
        // chooseSkuImg: that.data.product.image,
        skuMaxCount: sku.stock,
        chooseSkuTxt: sku.sku,
        // totalPrice:sku.price,
        // totalOtPrice:sku.otPrice
        totalPrice: Math.round(that.data.chooseSkuCount * sku.price * 100) / 100,  //sku.price ,
        totalOtPrice: Math.round(that.data.chooseSkuCount * sku.otPrice * 100) / 100,//sku.otPrice,
        
        proprietorSplit:proprietorSplit,
      })

      that.data.chooseSku = sku;
      // console.log('sku',sku);
    }
    return txt;
  },
  getChooseSkuAttr:function(){
    var that = this
    var skuattr = '';
    for (var index in that.data.productAttr){
      skuattr += that.data.productAttr[index].check_value_id + ',';
    }
    if (skuattr != ''){
      skuattr = skuattr.substring(0, skuattr.length - 1)
    }
    that.data.chooseSkuId = skuattr
  },
  //修改购买数量
  skuCountChange({ detail }) {
    var that = this
    console.log('skuCountChange',detail)
    console.log('that.data.chooseSku',that.data.chooseSku)
    
    if(that.data.chooseSku.price == undefined){
      Toast.fail('请选择规格');
      console.log(' detail - 1', detail - 1)
      that.data.chooseSkuCount = detail;
      that.setData({ chooseSkuCount: detail})
      return;
    }

    var isall_check = that.isAllCheck();
    console.log('isall_check',isall_check)
    if (isall_check) {
      that.data.chooseSkuCount = detail;
      that.setData({ chooseSkuCount: detail })
      that.setData({
        totalPrice:  Math.round(detail * that.data.chooseSku.price * 100) / 100,
        totalOtPrice: Math.round(detail * that.data.chooseSku.otPrice * 100) / 100,
      })
    } else {//未选择分类规格， 提示请选择
      Toast.fail('请选择规格');
    }
  },
  getClickPrice: function(count){
    var that = this
    var skus = that.data.skus
    var price = 0.00;
    var totalOtPrice = 0.00;
    for(var index in skus){
      console.log('that.data.chooseSkuAttr', that.data.chooseSkuAttr)
      console.log('skus[index].skuAttr', skus[index].skuAttr)
      if (that.data.chooseSkuAttr == skus[index].skuAttr){
        price = skus[index].price;
        totalOtPrice = skus[index].otPrice;
        that.setData({
          skuStock: skus[index].leftCount,
          chooseSkuImg: skus[index].imgUrl,
          totalPrice: Math.round(price * that.data.chooseSkuCount * 100) / 100,
          totalOtPrice: Math.round(totalOtPrice * that.data.chooseSkuCount * 100)/100  
        })
      }
    }
  },
  closeSku: function () {
    this.setData({  isShowSkuPop : false  })
  },
  goUserSaid: function () {
    wx.navigateTo({ url: '/pages/order/userSaid/index?id=' + this.data.id })
  },
  goBuy:function(e){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    var estate_id = app.getStorageSync("estate_id");
    var phone_num = app.getStorageSync("phone_num");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    }else {
      if(this.data.product.isNeedEstate == 1 && estate_id == 0){
        this.handleEstate();
      } else if(this.data.product.isNeedPhone == 1 && (phone_num== undefined || phone_num == '')){
        this.handlePhoneNum();
      }
       else{
        if(this.data.chooseSku.id > 0){
          if(this.data.chooseSkuCount <= 0){
            Toast.fail('数量不能为0');
            return;
          }
          that.setData({ visibleModal: false });
          this.onHttpBuy();
        }else{
          Toast.fail('请选择规格');
          return;
        }
      }
    }
  },
  handleEstate(){
    var that = this;
    var message = "请绑定小区后再进行购买"
    Dialog.confirm({
      title: '绑定小区',
      message
    }).then(() => {
      wx.navigateTo({
        url: '/pages/account/index?from_type=product',
      })
    })
    .catch(() => {
      Dialog.close();
    });
  },
  handlePhoneNum(){
    var that = this;
    var message = "请先绑定手机号后再进行购买哟~"
    Dialog.confirm({
      title: '温馨提醒',
      message
    }).then(() => {
      wx.navigateTo({
        url: '/pages/account/index?from_type=product',
      })
    })
    .catch(() => {
      Dialog.close();
    });
  },
  goHome(){
    wx.switchTab({
      url: '/pages/home/home',
    })
  },
  buySubmit: function (t) {
    var that = this
    console.log('buySubmit t', t)
    that.setData({ visibleModal: false });
    if(t.detail.index == 1){
      that.onHttpBuy()
    }
  },
  isAllCheck:function(){
    var isall_check = true
    for (var index in this.data.categorys) {
      if (this.data.categorys[index].check_value_id == '') {
        isall_check = false
      }
    }
    return isall_check;
  },
  goAddCart(e){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    var estate_id = app.getStorageSync("estate_id");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    } else {      
      if(this.data.product.isNeedEstate == 1 && estate_id == 0){
        this.handleEstate();
      }else{
        console.log('goAddCart',e);
        fetchApi.httpPost('/product/addCart', {
          product_id: that.data.chooseSku.productId,
          attr_value_id: that.data.chooseSku.id,
          count: that.data.chooseSkuCount,
          order_type: 0 //  
        }, function (res) {
          console.log("购买商品 ", res)
          if (res.data.code == 0) {
            var orderId = res.data.data
            wx.switchTab({
              url: '/pages/product/cart/index',
            })
          } else {
            console.log("购买商品 异常", res.data.msg)
            Toast.fail(res.data.msg)
          }
        }, function () {
          that.setData({ isLoading: false, loading: true, netWork: true, })
        })
      }
    }
  },
  goCart(){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    }else {
      wx.switchTab({
        url: '/pages/product/cart/index',
      })
    }
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpBuy: function () {
    if(this.data.product.isCanUseGolden == 1){
      Toast('暂未开放积分商品的购买');
      return;
    }

    var that = this
    fetchApi.httpPost('/product/order/addOrderBuyNow', {
      attr_value_id: that.data.chooseSku.id,
      count: that.data.chooseSkuCount,
      order_type: 0, //  积分商品订单
    }, function (res) {
      console.log("购买商品 ", res)
      if (res.data.code == 0) {
        var orderId = res.data.data
        wx.redirectTo({
          url: '/pages/pay/paySubmit/index?order_id=' + orderId
        })
      } 
      else if(that.data.product.isNeedEstate == 1 && res.data.code == 2){
        that.handleEstate();
      }
       else{
        console.log("购买商品 异常", res.data.msg)
        Toast.fail(res.data.msg)
      }
    }, function () {
      that.setData({ isLoading: false, loading: true, netWork: true, })
    })
  },
  getSkuIdBySkuAttr:function(){
    var that = this;
    var skuid = 0;
    for(var index in that.data.skus){
      if (that.data.chooseSkuId == that.data.skus[index].skuAttr){
        skuid = that.data.skus[index].id
      }
    }
    return skuid;
  },
  goCollection(res){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    }else {
      this.onHttpCollection(1)
    }
  },
  goUnCollection(res){
    var that = this;
    var isLogin = app.getStorageSync("isLogin");
    if (!isLogin) {
      wx.navigateTo({
        url: '/pages/login/index' + that.data.query + '&from_type=product&ag_id='+this.data.ag_id,
      })
    }else {
      this.onHttpCollection(0)
    }
  },
  /**
   * 联系客服人员 打电话 到客服
   */
  goCallMer(e){
    var that  = this
    console.log('that.data.mer',that.data.mer)
    wx.makePhoneCall({
      phoneNumber: that.data.mer.telphone,
    })
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpCollection: function (is_collect) {
    var that = this
    var url = "";
    if(is_collect == 0){//当前为已收藏   执行取消收藏
      url = '/user/collection/delete';
    }else{//当前为未收藏   执行收藏
      url = '/user/collection/add';
    }
    fetchApi.httpPost(url, {
      product_id: that.data.id,
      collection_type: 0 //  商品收藏
    }, function (res) {
      console.log("收藏商品 ", res)
      if (res.data.code == 0) {
        Toast.success(res.data.msg)
        
        if(is_collect == 0){//当前为已收藏   执行取消收藏
          that.setData({
            isCollect: false
          })
        }else{//当前为未收藏   执行收藏
          that.setData({
            isCollect: true
          })
        }

      } else {
        console.log("收藏商品 异常", res.data.msg)
        Toast.fail(res.data.msg)
      }
    }, function () {
      that.setData({ isLoading: false, loading: true, netWork: true, })
    })
  },
  onReady(){
    this.showQr()
  },
  showQr(){
    const query = wx.createSelectorQuery();
    query.select('#myCanvas')
    .fields({
      id: true,
      node: true,
      size: true
    }).exec(this.init.bind(this))
  },
  //init函数 通过 Canvas.getContext('2d') 接口可以获取 CanvasRenderingContext2D 对象，实现了 [HTML Canvas 2D Context](https://www.w3.org/TR/2dcontext/) 定义的属性、方法。
  init(res) {
    var that = this;
    console.log('init--------',res)
    const canvas = res[0].node
    const ctx = canvas.getContext('2d')
    const dpr = wx.getSystemInfoSync().pixelRatio;//获取屏幕的像素比  值为2
     //新接口需显示设置画布宽高； w*2 h*2
     canvas.width = res[0].width * dpr;
     canvas.height = res[0].height * dpr;
     ctx.scale(dpr, dpr); //缩放

     this.setData({
      canvas,
      ctx
    });
    //渲染bg图片和二维码还有文字，必须按照顺序来，先渲染背景，再渲染logo，最后渲染文字，如果顺序不统一，logo先渲染，就会导致背景图片加载不出来。
    //向画布载入图片的方法
    setTimeout(function(){
      that.canvasDraw(ctx,canvas).then(res=>{
        console.log('1',res)
          // 向画布载入logo的方法
        // return that.code(ctx)
      }).then(rrr=>{
        console.log('2',rrr)
        //图片头像渲染完成之后，渲染文字
        that.title(ctx)
      })
    },1000)
  },
  // 封面图  使用 pormise方法来输出 代码执行成功，返回一个成功标识出去
  canvasDraw(ctx,canvas) {
    var that = this;
    this.data.ctx = ctx;
    this.data.canvas = canvas;
    return new Promise(res=>{
      console.log('canvasDraw',res)
      let img = that.data.canvas.createImage(); //创建img对象
      img.src = that.data.product.image;
      img.onload = () => {
        // console.log(img.complete); //true
        that.data.ctx.drawImage(img, 0, 0,480, 370);
        setTimeout(() => {
          res(true)
        }, 100);
      };  
    })
  },
  //文字模块，不使用pormise，因为他是最后模块，所有不需要了
  title(ctx) {
    var that = this;
      let text = "抢购价 ￥" + this.data.product.labelPrice;
      ctx.font = 'normal bold 50px sans-serif';
      // ctx.fillStyle = "rgba(60, 59, 59)";
      console.log('======,', text.length)
      ctx.fillStyle = "red";//添加颜色
      ctx.fillText(text, 120, 100, 300)
      setTimeout(function(){
        that.downloadQrCode()
      },500);
  },
  downloadQrCode() {
    // 保存到相册
    var that = this;
    console.log('保存canvasId',this.data.canvas._canvasId);
    let w = 480 * this.data.scale;
    let h = 270 * this.data.scale;
    wx.canvasToTempFilePath({     //将canvas生成图片
      canvas:that.data.canvas,
      // x: 0,
      // y: 0,
      // width: w,
      // height: w,
      // destWidth: w * 2,     //截取canvas的宽度
      // destHeight: h*2,   //截取canvas的高度
      success: function (res) {
        console.log('生成图片成功：',res)
        that.data.shareImg = res.tempFilePath;
        // that.data.imgUrls.push(res.tempFilePath)
        // that.setData({
        //   imgUrls: that.data.imgUrls
        // })
      },
      fail:function(res){
        console.log('保存图片报错',res)
        that.setData({
          flag:false
        })
      }
    },this)
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var product_id = this.data.id;
    var user_id = app.getStorageSync("user_id");
    console.log( "转发成功 user_id",user_id)
    var title = "【抢购价￥"+ that.data.product.labelPrice+"】" + that.data.product.storeName;
    
    return {
      title: title,
      path: '/pages/product/detail/index?id='+product_id+'&ag_id='+user_id,
      imageUrl: that.data.shareImg,
      success: function (res) {
        console.log(res, "转发成功")
      },
      fail: function (res) {
        console.log(res, "转发失败")
      }
    }
  },
})
